/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Button, TextArea, Text, useToast,} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {render容积换热, view容积} from "./rarelyVary";
import {input设计温度} from "../../vessel/Annual/orcBase";
import {itemA下结论} from "./Conclusion";
import {itemA检验项} from "./InspectionItem";

export const 施工类别选=['新装','移装'];
export const config设备概况 = [
    [['使用单位', '_$使用单位'], ['联系人', '_$单位联系人'] ],
    [['使用单位地址', '_$使用单位地址'], ['邮政编码', '_$使用单位邮编'] ],
    [['容器安装地点', '_$设备使用地点'],  ['联系电话', '_$使用单位电话'], ],
    [['制造单位', '_$制造单位'], ['容器类别', '_$设备品种'] ],
    [['容器名称', '_$设备名称'], ['制造日期', '_$制造日期']],
    //拆分
    [['产品编号', '_$出厂编号'], ['单位内部编号/位号', '_$单位内部编号',],  ],
    [['设计压力',  '_$设计压力', 'MPa'], ['工作压力', '_$工作压力','MPa'],  ],
    //设计温度==臺賬 現有字段組合的？？
    [['设计温度', {n:'设计温度',u:'℃'}, input设计温度], ['工作温度', '_$工作温度','℃'], ],
    [['设计介质', '_$设计介质'],  ['工作介质', '_$工作介质'] ],
    [['压力容器规格', '_$容器规格','mm'], [{t:'容积', view:view容积, pr:null}, '_$容积换热', render容积换热], ],
        //不用台账的安装单位？
    [['安装单位', {n:'安装单', t:'B'}], ],
    [['安装许可证编号', '安许可号'],['联系人/电话', {n:'安装系电', t:'B'}] ],
    //新装 移装的？
    [['施工类别',{n:'施工类别',t:'l',l:施工类别选}], ['竣工日期', {n:'竣工日', t:'d'}] ],
    [['施工起始日期', {n:'施起日', t:'d'}], ['检验起始日期', '_$检验日期1'], ],
    //下结论页面的录入：检验日期1
    [['施工结束日期', {n:'施结日', t:'d'}], ['检验结束日期', '_$检验日期' ], ],
    [['检验依据', {r:'TSG 21-2016《固定式压力容器安全技术监察规程》'} ],  ],
];

export const EntranceSetup =
    React.forwardRef((
        {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
    ) => {
        const atPrint = useMedia('print');
        const toast = useToast();
        const doCheckNames = React.useCallback((verId: string) => {
            const result = assertNamesUnique([{value: rep?.tzFields},
                {value: config设备概况, type:'esnt'},
                {value:[...itemA下结论, ...itemA检验项, ]},
                {value:['Projects',  ]}
                ]);
            toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
        }, [rep,toast]);
        const {storage, setStorage} =React.useContext(EditStorageContext) as any;
        const getInpFilter = React.useCallback((par: any) => {
            const {_tblFixed, } =par||{};
            return {_tblFixed, };
        }, []);
        const {inp, setInp} = useItemInputControl({ref});
        if (atPrint) return null;
        else return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={'初始化本报告，默认值配置等'}>
                {process.env.REACT_APP_TEST==='true' && <><div>
                    <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                    <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                    <Text variant="h5">设置待测试表格的各列宽度：</Text>
                    <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                        JSON.parse(e.currentTarget.value??'[]');
                        setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
                </div></>
                }
                <hr/>
            </InspectRecordLayout>
        );
});
